<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>存在重复元素</title>
</head>
<body>
  <script>
    function fn(nums) {
      nums.sort((a, b) => a - b);
      const n = nums.length;
      for (let i = 0; i < n - 1; i++) {
        if (nums[i] === nums[i + 1]) {
          return true
        }
      }
      return false
    }
    console.log(fn([1, 2, 3, 1]))
  </script>
</body>
</html>